define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'manage/checkrecord/index' + location.search,
                    // add_url: 'manage/checkrecord/add',
                    // edit_url: 'manage/checkrecord/edit',
                    // del_url: 'manage/checkrecord/del',
                    // multi_url: 'manage/checkrecord/multi',
                    // import_url: 'manage/checkrecord/import',
                    recordlist_url: 'manage/checkrecord/recordlist',
                    table: 'check_record',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                searchFormVisible:true,
                search:false,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id'),operate: false},
                        {field: 'date', title: __('Date'), operate: false},
                        {field: 'checkplan', title: __('Checkplan'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'checkplan_detail_start_time', title: __('Checkplan_detail_start_time'), operate: false},
                        {field: 'checkplan_detail_end_time', title: __('Checkplan_detail_end_time'), operate: false},
                        {field: 'check_user', title: __('Check_user'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'real_check_user', title: __('Real_check_user'), operate: false},
                        {field: 'checkpoint', title: __('Checkpoint'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'check_time', title: __('Check_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
                        {field: 'check_pics', title: __('Check_pics'), formatter:Table.api.formatter.image,events: Table.api.events.image},
                        {field: 'is_abnormal', title: __('Is_abnormal'),formatter: Table.api.formatter.status, searchList: {1: __('Is_abnormal 1'), '2': __('Is_abnormal 2')}},
                        {field: 'abnormal_desc', title: __('Abnormal_desc'), operate: false},
                        {field: 'next_checkpoint', title: __('Next_checkpoint'), operate: false},
                        {field: 'create_time', title: __('Create_time'), operate: false}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);


        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        detail: function () {
            Controller.api.bindevent();
        },
        recordlist: function () {
            Table.api.init({
                extend: {
                    // index_url: 'manage/checkrecord/index' + location.search,
                    // add_url: 'manage/checkrecord/add',
                    // edit_url: 'manage/checkrecord/edit',
                    // del_url: 'manage/checkrecord/del',
                    // multi_url: 'manage/checkrecord/multi',
                    detail: 'manage/checkrecord/detail',
                    recordlist_url: 'manage/checkrecord/recordlist'+ location.search,
                    table: 'check_record',
                }
            });
            var table = $("#recordlist");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.recordlist_url,
                pk: 'checkplan_detail_id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                searchFormVisible:true,
                search:false,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'check_user_id', title: __('Check_user_id'),operate: false},
                        {field: 'check_user', title: __('Check_user'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'checkplan', title: __('Checkplan'),operate: false },
                        {field: 'date', title: __('Date'), operate:'=', addclass:'datetimepicker', autocomplete:false,formatter: Table.api.formatter.datetime, data: 'data-date-format="YYYY-MM-DD"'},
                        {field: 'checkplan_detail_start_time', title: __('Checkplan_detail_start_time'),visible:false, operate:'=', addclass:'datetimepicker', autocomplete:false,formatter: Table.api.formatter.datetime, data: 'data-date-format="H:mm"'},
                        {field: 'checkplan_detail_end_time', title: __('Checkplan_detail_end_time'), visible:false,operate:'=', addclass:'datetimepicker', autocomplete:false,formatter: Table.api.formatter.datetime, data: 'data-date-format="H:mm"'},
                        {field: 'checkplan_detail_time', title: __('Checkplan_detail_time'),formatter: function (value,row,index){
                                return row.checkplan_detail_start_time+' ~ '+row.checkplan_detail_end_time;
                            },operate: false},

                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate, buttons: [
                                {name: 'goods', text: '查看详情', title: '查看详情',  classname: 'btn btn-xs btn-success btn-dialog', url: "manage/checkrecord/detial?checkplan_detail_id={checkplan_detail_id}&&checkdate={date}&&checkplan_id={checkplan_id}"},

                            ]}

                    ]
                ]
            });

            // 为表格绑定事件


            Controller.api.bindevent();
        },

        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };

    return Controller;
});
